#ifndef PROJECT_JS
#define PROJECT_JS

#include "Directory.js"
#include "File.js"

var Project = function(/* XmlNode */ node)
{
	if (node.xmlns == undefined ||
		node.xmlns != "http://objective-javascript.googlecode.com/files/Ojsproj.xsd")
	{
		throw "Invalid file.";
	}
	
	var /* OutputConfig */ _outputConfig = null;
	var /* Directory[] */ _directories = new Array();
	var /* File[] */ _files = new Array();
	
	var /* string */ _outputDirectory = ".";
	var /* string */ _outputName;
	var /* string */ _executableEntryPoint = "";
	
	(function()
	{
		if (node.Directory != undefined)
		{
			for(var i = 0; i < node.Directory.length; i++)
			{
				_directories.push(new Directory(node.Directory[i]));
			}
		}
		
		if (node.File != undefined)
		{
			for(var i = 0; i < node.File.length; i++)
			{
				_files.push(new File(node.File[i]));
			}
		}

		if (node.OutputDirectory != undefined)
		{
			_outputDirectory = node.OutputDirectory;
		}
		
		if (node.ExecutableEntryPoint != undefined)
		{
			_executableEntryPoint = node.ExecutableEntryPoint;
		}
		
		if (node.OutputName != undefined)
		{
			_outputName = node.OutputName;
		}
		else
		{
			throw "Missing required attribute 'OutputName'.";
		}
	})();
	
	this.__defineGetter__("Directories", function() { return _directories; });
	this.__defineGetter__("Files", function() { return _files; });
	this.__defineGetter__("OutputDirectory", function() { return _outputDirectory; });
	this.__defineGetter__("OutputName", function() { return _outputName; });
	this.__defineGetter__("ExecutableEntryPoint", function() { return _executableEntryPoint; });
};

(function()
{
	/* Project */ Project.Load = function(/* string */ fileName)
	{
		var fs = require("fs");
		var xml2js = require("xml2js");
		var parser = new xml2js.Parser({trim:false, normalize:false, explicitRoot:true, explicitArray:true, mergeAttrs:true});
		var data = fs.readFileSync(fileName, "utf-8");
		var project;
		
	    parser.parseString(data, function (err, result) {
	        if (err != null)
	        {
	        	throw "Parsing ojsproj file failed.";
	        }
	        
	        if (result.Project != undefined)
	        {
	        	project = new Project(result.Project);
	        }
	        else
	        {
	        	throw "Invalid file.";
	        }
	    });
	    
	    return project;
	};
})();

#endif
